home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / mas.lha / MAS / sub.asm < prev   
Assembly Source File  |  1995-07-18  |  3KB  |  126 lines

  1. ; SH-Ware assembly routines for C by S.Klemola
  2.  
  3. Lib MACRO * function[,basereg]
  4.          xref _LVO\1
  5.          ifnc '\2',''
  6.          movea.l \2,a6
  7.          endc
  8.          jsr _LVO\1(a6)
  9.          ENDM
  10.  
  11.          section SH-Funcs,code
  12.          near a4
  13.  
  14.          xref _DOSBase     ; External reference to the base of dos.library
  15.  
  16.          xdef _rawprint    ; prints an unformatted string
  17.          xdef _print       ; formats a string and calls _rawprint
  18.          xdef _sprint      ; formats a string and puts it into a buffer
  19.          xdef _strcmp
  20.          xdef _strcpy
  21.          xdef _strlen
  22.          xdef _clear
  23.  
  24. _rawprint         ; ULONG rawprint(string)
  25.  
  26.          movea.l  4(sp),a1
  27.  
  28. _raw1    movem.l  d2/d3/a6,-(sp)    ; registered entry point (A1=string)
  29.          move.l   a1,d2
  30.          moveq    #-1,d3
  31. _raw2    addq.l   #1,d3
  32.          tst.b    (a1)+
  33.          bne      _raw2
  34.          Lib      Output,_DOSBase(a4)
  35.          move.l   d0,d1
  36.          Lib      Write
  37. _raw3    movem.l  (sp)+,d2/d3/a6
  38.          rts
  39.  
  40. _print            ; ULONG print(string[,arg][,arg][...])
  41.  
  42.          movem.l  d4/a2-a4/a6,-(sp)
  43.          clr.l    d0
  44.          bset.l   #9,d0
  45.          clr.l    d1
  46.          Lib      AllocMem,4
  47.          movea.l  d0,a3
  48.          tst.l    d0
  49.          beq      _pri1
  50.          movea.l  24(sp),a0
  51.          lea      28(sp),a1
  52.          lea      _pri2(pc),a2
  53.          Lib      RawDoFmt
  54.          movea.l  a3,a1
  55.          bsr      _raw1
  56.          move.l   d0,d4
  57.          movea.l  a3,a1
  58.          clr.l    d0
  59.          bset.l   #9,d0
  60.          Lib      FreeMem,4
  61.          move.l   d4,d0
  62. _pri1    movem.l  (sp)+,d4/a2-a4/a6
  63.          rts
  64. _pri2    move.b   d0,(a3)+
  65. _rts     rts
  66.  
  67. _sprint           ; ULONG sprint(buffer,string[,arg][,arg][...])
  68.  
  69.          movem.l  d4/a2-a4/a6,-(sp)
  70.          tst.l    24(sp)
  71.          beq      _pri1
  72.          movea.l  24(sp),a3
  73.          movea.l  28(sp),a0
  74.          lea      32(sp),a1
  75.          lea      _pri2(pc),a2
  76.          Lib      RawDoFmt,4
  77.          movea.l  a3,a0
  78.          bsr      _strlen1
  79.          bra      _pri1
  80.  
  81. _strcmp           ; ULONG strcmp(string,string)
  82.  
  83.          movea.l  4(sp),a0
  84.          movea.l  8(sp),a1
  85. _strcmp1 clr.l    d0
  86. compb    move.b   (a0)+,d1
  87.          bne      compc
  88.          tst.b    (a1)
  89.          beq      compa
  90.          bne      compd
  91. compc    cmp.b    (a1)+,d1
  92.          beq      compb
  93. compd    moveq    #1,d0
  94. compa    rts
  95.  
  96. _strcpy           ; LONG strcpy(buffer,string)
  97.  
  98.          movea.l  4(sp),a1
  99.          movea.l  8(sp),a0
  100. _strcpy1 clr.l    d0
  101. _strcpy2 move.b   (a0)+,(a1)+
  102.          beq      _rts
  103.          addq.l   #1,d0
  104.          bra      _strcpy2
  105.  
  106. _strlen           ; LONG strlen(string)
  107.  
  108.          movea.l  4(sp),a0
  109. _strlen1 clr.l    d0
  110. _strlen2 tst.b    (a0)+
  111.          beq      _rts
  112.          addq.l   #1,d0
  113.          bra      _strlen2
  114.  
  115. _clear            ; void clear(buffer,length)
  116.  
  117.          movea.l  4(sp),a0
  118.          move.l   8(sp),d0
  119.          beq      _rts
  120.          subq.l   #1,d0
  121.          beq      _rts
  122. _clear1  clr.b    (a0)+
  123.          dbf      d0,_clear1
  124.          rts
  125.  
  126.